import request from '@/utils/request'

// 模拟数据
const mockData = {
  // 标准参数列表
  paramList: [
    {
      id: 1,
      standardId: 1,
      name: "重量",
      type: "数值",
      nominalValue: "100",
      minValue: "95",
      maxValue: "105",
      unit: "g"
    },
    {
      id: 2,
      standardId: 1,
      name: "长度",
      type: "数值",
      nominalValue: "50",
      minValue: "48",
      maxValue: "52",
      unit: "mm"
    }
  ],
  // 标准参数详情
  paramDetail: {
    id: 1,
    standardId: 1,
    name: "重量",
    type: "数值",
    nominalValue: "100",
    minValue: "95",
    maxValue: "105",
    unit: "g"
  }
};

// 使用模拟数据响应
const useMockData = true;

// 查询标准参数列表
export function listStandardParam(query) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      rows: mockData.paramList,
      total: mockData.paramList.length
    });
  }
  
  return request({
    url: '/qep/standardParam/list',
    method: 'get',
    params: query
  })
}

// 查询标准参数详细
export function getStandardParam(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      data: mockData.paramDetail
    });
  }
  
  return request({
    url: '/qep/standardParam/' + id,
    method: 'get'
  })
}

// 新增标准参数
export function addStandardParam(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standardParam',
    method: 'post',
    data: data
  })
}

// 修改标准参数
export function updateStandardParam(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standardParam',
    method: 'put',
    data: data
  })
}

// 删除标准参数
export function delStandardParam(id) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standardParam/' + id,
    method: 'delete'
  })
}

// 批量添加标准参数
export function batchAddStandardParam(data) {
  if (useMockData) {
    return Promise.resolve({
      code: 200,
      msg: "操作成功"
    });
  }
  
  return request({
    url: '/qep/standardParam/batchAdd',
    method: 'post',
    data: data
  })
} 